/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package FourShTests;

import Rout.*;
import java.io.File;
//import com.sun.javafx.scene.layout.region.RepeatStruct;
import org.jboss.netty.channel.ChannelHandler;
import org.testng.annotations.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;

/**
 *
 * @author user
 */
public class Shared4XRXFast {

    private GoBefore browser = new GoBefore();

    @BeforeMethod
    public void setUp() throws Exception {

        System.out.println("\n Run test: " + getClass().getSimpleName());
        browser.setXpFilename("/html/body/div[7]/div/div/div[2]/h1");
        browser.setCurURL("http://www.4shared.com/photo/jIP-_j8sce/Test_file.html");
        browser.setLpurl("secured");
        

        String dir = "screenshots";
        String srcDir = (new File("").getAbsolutePath() + "/" + dir + "/");
        File folder = new File(srcDir);
        File[] listOfFiles = folder.listFiles();
        for (int i = 0; i < listOfFiles.length; i++) {
            System.out.println("delete old screenshots: " + listOfFiles[i].getName());
            listOfFiles[i].delete();           
        }        
    }

    @Test //XRX
    public void XRX() throws Exception {

        browser.setCssButton("#downloadHelperLink > div");
        browser.setClButton("helperButtonGradient");
        browser.setXpButton("//*[@id=\"downloadHelperLink\"]/div");

        browser.setUp();
        browser.setRepDir(getClass().getSimpleName());
        //scroll
        for (int i = 0; i < 1; i++) {
        browser.getClicker().sendKeys(Keys.PAGE_DOWN).perform();
        }

        //sleep
        Thread.sleep(3000);

        browser.testRun();
        //sleep
        Thread.sleep(1000);

        browser.lpDetect();
        browser.verFilePresent();
        browser.verFilename();

    }

    @AfterMethod
    public void Down() throws Exception {
                try {
            CleanDir cle = new CleanDir();
            cle.clearAll("C:\\Users\\user\\Downloads\\", true);
            System.out.println("downoad dir "+ cle.getDirName() +" now clear");
        } catch (Exception e) {
            System.out.println("something wrong" + e);
        }
        browser.getDriver().quit();

    }

}
